﻿<Window x:Class="ClearMine.Dialogs.OptionsDialog" x:ClassModifier="internal"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:f="clr-namespace:ClearMine.Framework;assembly=ClearMine.Framework"
        xmlns:c="clr-namespace:ClearMine.Framework.Converters;assembly=ClearMine.Framework"
        xmlns:h="clr-namespace:ClearMine.Framework.Controls;assembly=ClearMine.Framework"
        xmlns:m="clr-namespace:ClearMine.GameDefinition;assembly=ClearMine.GameDefinition"
        xmlns:t="clr-namespace:ClearMine.Framework.Controls;assembly=ClearMine.Framework"
        t:WindowExt.ResizeMode="NoResize"
        h:CommandsHelper.LoadBindingsFromVM="True"
        Background="{StaticResource DialogBackground}"
        TextOptions.TextFormattingMode="Display"
        WindowStartupLocation="CenterOwner"
        SizeToContent="WidthAndHeight"
        ShowInTaskbar="False"
        ResizeMode="NoResize"
        Style="{DynamicResource MainWindowStyle}"
        Title="{DynamicResource OptionsDialogTitle}">
    <Window.Resources>
        <c:DifficultyToBooleanConverter x:Key="DifficultyToBooleanConverter" />
    </Window.Resources>
    <Window.CommandBindings>
        <x:Static Member="f:UICommandBindings.CloseBinding" />
    </Window.CommandBindings>
    <!-- Pay attention to the focus sequence when update xaml. -->
    <StackPanel Margin="12">
        <GroupBox Header="{DynamicResource DifficultySettingsGroupLabel}"
                  Style="{StaticResource SeparatorGroupBoxStyle}">
            <DockPanel>
                <StackPanel Orientation="Horizontal"
                            Margin="0,0,0,7"
                            DockPanel.Dock="Top">
                    <RadioButton Content="{DynamicResource BeginnerLevelLabel}"
                                 Margin="0,0,7,0"
                                 IsChecked="{Binding Difficulty, Converter={StaticResource DifficultyToBooleanConverter}, ConverterParameter=Beginner}"
                                 GroupName="difficulty" />
                    <RadioButton Content="{DynamicResource IntermediateLevelLabel}"
                                 Margin="0,0,7,0"
                                 IsChecked="{Binding Difficulty, Converter={StaticResource DifficultyToBooleanConverter}, ConverterParameter=Intermediate}"
                                 GroupName="difficulty" />
                    <RadioButton Content="{DynamicResource AdvancedLevelLabel}"
                                 IsChecked="{Binding Difficulty, Converter={StaticResource DifficultyToBooleanConverter}, ConverterParameter=Advanced}"
                                 GroupName="difficulty" />
                </StackPanel>
                <DockPanel>
                    <RadioButton x:Name="customChecker"
                                 Content="{DynamicResource CustomDifficultyLabel}"
                                 Margin="0,0,0,5"
                                 DockPanel.Dock="Top"
                                 IsChecked="{Binding Difficulty, Converter={StaticResource DifficultyToBooleanConverter}, ConverterParameter=Custom}"
                                 GroupName="difficulty" />
                    <Grid IsEnabled="{Binding IsChecked, ElementName=customChecker, Mode=OneWay}"
                          Margin="18,0,12,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="5" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="5" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Label Content="{DynamicResource CustomHeightLabel}"
                               Grid.Row="0" />
                        <Label Content="{DynamicResource CustomWidthLabel}"
                               Grid.Row="2" />
                        <Label Content="{DynamicResource CustomMinesLabel}"
                               Margin="0,0,5,0"
                               Grid.Row="4" />
                        <TextBox Grid.Column="1"
                                 Grid.Row="0"
                                 MaxLength="2"
                                 ToolTip="{Binding Path=(Validation.Errors)[0].ErrorContent, RelativeSource={RelativeSource Self}}"
                                 Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}"
                                 Text="{Binding Rows, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBox Grid.Column="1"
                                 Grid.Row="2"
                                 MaxLength="2"
                                 Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}"
                                 ToolTip="{Binding Path=(Validation.Errors)[0].ErrorContent, RelativeSource={RelativeSource Self}}"
                                 Text="{Binding Columns, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBox Grid.Column="1"
                                 Grid.Row="4"
                                 MaxLength="3"
                                 Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}"
                                 ToolTip="{Binding Path=(Validation.Errors)[0].ErrorContent, RelativeSource={RelativeSource Self}}"
                                 Text="{Binding Mines, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>
                </DockPanel>
            </DockPanel>
        </GroupBox>
        <GroupBox Header="{DynamicResource GameEffectGroupLabel}"
                  Style="{StaticResource SeparatorGroupBoxStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <CheckBox Content="{DynamicResource PlaySoundLabel}"
                          IsChecked="{Binding PlaySound}" />
                <CheckBox Content="{DynamicResource PlayAnimationLabel}"
                          Grid.Column="1"
                          IsChecked="{Binding PlayAnimation}" />
                <CheckBox Content="{DynamicResource WavingFlagEffect}"
                          Grid.Row="2"
                          IsChecked="{Binding WavingFlag}" />
                <CheckBox Content="{DynamicResource ShowAccurateTime}"
                          Grid.Row="2" Grid.Column="1"
                          IsChecked="{Binding AccurateTime}" />
            </Grid>
        </GroupBox>
        <GroupBox Header="{DynamicResource GameControlGroupLabel}"
                  Style="{StaticResource SeparatorGroupBoxStyle}">
            <StackPanel>
                <CheckBox Content="{DynamicResource ShowQuestionMarkLabel}"
                          IsChecked="{Binding ShowQuestionMark}"
                          Margin="0,0,0,5" />
                <CheckBox Content="{DynamicResource AlwaysNewGameLabel}"
                          IsChecked="{Binding AlwaysNewGame}"
                          Margin="0,0,0,5" />
                <CheckBox Content="{DynamicResource AlwaysSaveGameLabel}"
                          IsChecked="{Binding SaveOnExit}"
                          Margin="0,0,0,5" />
                <CheckBox Content="{DynamicResource AlwaysContinueGameLabel}"
                          IsChecked="{Binding AutoContinueSaved}"
                          Margin="0,0,0,5" />
                <CheckBox Content="{DynamicResource ShowTooManyFlagsWarning}"
                          IsChecked="{Binding ShowTooManyFlagsWarning}" />
            </StackPanel>
        </GroupBox>
        <GroupBox Header="{DynamicResource GameHistoryGroupLabel}"
                  Margin="0,0,0,12"
                  Style="{StaticResource SeparatorGroupBoxStyle}">
            <Grid Margin="0,0,12,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <CheckBox Content="{DynamicResource SaveGameHistoryLabel}"
                          Margin="0,0,0,5"
                          Grid.ColumnSpan="2"
                          IsChecked="{Binding SaveGame}" />
                <TextBox Margin="18,0,0,0"
                         MinWidth="150"
                         Grid.Row="1"
                         Text="{Binding GameHistoryFolder, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
                         IsEnabled="{Binding SaveGame}" />
                <Button Content="{DynamicResource BrowseGameHistoryLabel}"
                        Margin="5,0,0,0"
                        Grid.Column="1"
                        Grid.Row="1"
                        Command="{x:Static m:GameCommands.BrowseHistory}" />
            </Grid>
        </GroupBox>
        <StackPanel Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Content="{DynamicResource OKButtonLabel}"
                    IsDefault="True"
                    Command="Save"
                    Margin="0,0,7,0" />
            <Button Content="{DynamicResource CancelButtonLabel}"
                    IsCancel="True"
                    Command="Close" />
        </StackPanel>
    </StackPanel>
</Window>
